package com.cpic.rxjava;

import android.os.Handler;
import android.os.Looper;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public enum SchedulerService {
    INSTANCE;

    private    ExecutorService executorService =  Executors.newCachedThreadPool();
    private    Handler MAIN_HANDLER = new Handler(Looper.getMainLooper());

    public void runThread(Runnable runnable){
        executorService.execute(runnable);
    }


    public void runMain(Runnable runnable){
        MAIN_HANDLER.post(runnable);
    }

    public void run(Runnable runnable, int threadFlag){
        switch (threadFlag){
            case  -1:
            executorService.execute(runnable);
            break;
            case 0:
            runnable.run();
            break;
            case 1:
            MAIN_HANDLER.post(runnable);
            break;
        }
    }
}
